package com.ltkj.coupon.controller;

import com.ltkj.common.core.domain.R;
import com.ltkj.common.core.utils.poi.ExcelUtil;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.web.page.TableDataInfo;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.annotation.RequiresPermissions;
import com.ltkj.coupon.domain.TCouponTemp;
import com.ltkj.coupon.domain.dto.TCouponTempAddDTO;
import com.ltkj.coupon.domain.vo.CouponSelectVo;
import com.ltkj.coupon.service.ITCouponTempService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 优惠券模板Controller
 * 
 * @author ruoyi
 * @date 2023-09-21
 */
@Api(tags = "优惠券模板")
@RestController
@RequestMapping("/coupontem")
public class TCouponTempController extends BaseController
{
    @Autowired
    private ITCouponTempService tCouponTempService;

    /**
     * 查询优惠券模板列表
     */
    @ApiOperation("查询优惠券模板列表")
    @RequiresPermissions("coupontem:coupontem:list")
    @GetMapping("/list")
    public TableDataInfo list(TCouponTemp tCouponTemp)
    {
        startPage();
        tCouponTemp.setIsDel("0");
        List<TCouponTemp> list = tCouponTempService.selectTCouponTempList(tCouponTemp);
        return getDataTable(list);
    }

    /**
     * 导出优惠券模板列表
     */
    @ApiOperation("导出优惠券模板列表")
    @RequiresPermissions("coupontem:coupontem:export")
    @Log(title = "优惠券模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCouponTemp tCouponTemp)
    {
        List<TCouponTemp> list = tCouponTempService.selectTCouponTempList(tCouponTemp);
        ExcelUtil<TCouponTemp> util = new ExcelUtil<TCouponTemp>(TCouponTemp.class);
        util.exportExcel(response, list, "优惠券模板数据");
    }

    /**
     * 获取优惠券模板详细信息
     */
    @ApiOperation("获取优惠券模板详细信息")
    @RequiresPermissions("coupontem:coupontem:query")
    @GetMapping(value = "/{id}")
    public R<TCouponTempAddDTO> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(tCouponTempService.selectTCouponTempByIdV2(id));
    }

    // /**
    //  * 新增优惠券模板
    //  */
    // @ApiOperation("新增优惠券模板")
    // @RequiresPermissions("coupontem:coupontem:add")
    // @Log(title = "优惠券模板", businessType = BusinessType.INSERT)
    // @PostMapping
    // public AjaxResult add(@RequestBody TCouponTemp tCouponTemp)
    // {
    //     return toAjax(tCouponTempService.insertTCouponTemp(tCouponTemp));
    // }

    /**
     * 新增优惠券模板
     */
    @ApiOperation("新增优惠券模板")
    @RequiresPermissions("coupontem:coupontem:add")
    @Log(title = "优惠券模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCouponTempAddDTO tCouponTempAddDTO)
    {
        return toAjax(tCouponTempService.insertTCouponTempAdd(tCouponTempAddDTO));
    }

    /**
     * 修改优惠券模板
     */
    @ApiOperation("修改优惠券模板")
    @RequiresPermissions("coupontem:coupontem:edit")
    @Log(title = "优惠券模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCouponTempAddDTO tCouponTempAddDTO)
    {
        return toAjax(tCouponTempService.updateTCouponTempV2(tCouponTempAddDTO));
    }

    /**
     * 删除优惠券模板
     */
    @ApiOperation("删除优惠券模板")
    @RequiresPermissions("coupontem:coupontem:remove")
    @Log(title = "优惠券模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tCouponTempService.deleteTCouponTempByIds(ids));
    }


    /**
     * 优惠券模板下拉
     */
    @ApiOperation("优惠券模板下拉")
    // @RequiresPermissions("coupontem:coupontem:select")
    @GetMapping("/select")
    public R<List<CouponSelectVo>> select()
    {
        return tCouponTempService.select();
    }
}
